<template>
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb separator="/">
      <!-- <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item> -->
      <el-breadcrumb-item>项目管理</el-breadcrumb-item>
      <el-breadcrumb-item>项目列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片区 -->
    <el-card>
      <el-row>
        <el-col :span="7">
          <el-input placeholder="请输入项目名称" v-model="queryInfo.query" @keyup.enter="getItemList()" clearable @clear="getItemList()">
            <template #append><el-button icon="el-icon-search" @click="getItemList()"></el-button></template>
          </el-input>
        </el-col>
        <el-col :span="14"></el-col>
        <el-col :span="3">
          <el-button style="width:100%;padding:1px" type="primary" icon="el-icon-plus" @click="addDialogVisible=true">添加</el-button>
        </el-col>
      </el-row>
      <!-- 列表区域 -->
      <el-table :data="itemList" stripe border style="width: 100%">
        <el-table-column type="index" label="序号"></el-table-column>
        <el-table-column label="项目名称" prop="itemName"></el-table-column>
        <el-table-column label="项目负责人" prop="itemAdmin"></el-table-column>
        <!-- 项目没有状态 无需注销 -->
        <!-- <el-table-column label="操作">
          <template v-slot="scope">
            <el-button size="mini" type="danger" icon="el-icon-delete" :disabled="scope.row.status">注销</el-button>
          </template>
        </el-table-column> -->
      </el-table>

      <!-- 分页 区域 -->
      <el-config-provider :locale="locale">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="queryInfo.pagenum"
          :page-sizes="[1, 2, 5, 10]"
          :page-size="queryInfo.pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        ></el-pagination>
      </el-config-provider>
    </el-card>

    <el-dialog v-model="addDialogVisible" title="添加项目" width="50%">
      <el-form :model="addForm" :rules="addFormRules" ref="addFormRef" label-width="100px">
        <el-form-item label="项目名称" prop="itemname">
          <el-input v-model="addForm.itemname"></el-input>
        </el-form-item>
        <el-form-item label="项目负责人" prop="mobile">
          <!-- <el-input v-model="addForm.itemman"></el-input> -->
          <!-- 项目负责人可以从 属于该公司且岗位为项目负责人的人中选择 以下拉框-->
        </el-form-item>
      </el-form>
      <!-- 底部 -->
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="addDialogVisible = false">取消</el-button>
          <el-button type="primary" @click="addItem(addForm)">确定</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import zhCn from "element-plus/lib/locale/lang/zh-cn";
export default {
  data(){
    return{
      queryInfo:{
        query:"",
        pagenum: 1,
        pagesize: 5
      },
      itemList:[],
      total:0,
      addDialogVisible:false,
      addForm:{},
      addFormRules:{}
    }
  },
  setup(){
    return{
      locale:zhCn
    }
  },
  mounted(){
    this.getItemList();
  },
  methods:{
     async getItemList() {
      const { data: res } = await this.$http.get("companyItem/getItemList", {params: this.queryInfo});
      if (res.meta.status !== 200)
        return this.$message.error("获取项目列表失败！");
      this.itemList = res.data.users;
      this.total = res.data.total;
    },
    handleSizeChange(newSize) {
      this.queryInfo.pagesize = newSize;
      this.getItemList();
    },
    handleCurrentChange(newPage) {
      this.queryInfo.pagenum = newPage;
      this.getItemList();
    },
    addItem(form){
      console.log(form);
    },
  }
}
</script>

<style lang="less" scoped>

</style>
